const app = getApp();
Page({
	data: {
		roomName:'',
		userName: '',
    tapTime: '',
    roomPassWord:'',
    classa: (app.tabbarindex === 0 ? false : true) || app.siteInfo.tabbar_type === '2',
	},
	bindRoomName: function (e) {
    let self = this;
		self.setData({
      roomName: e.detail.value,
		});
	},
  bindRoomPassWord (e) {
		this.setData({
      roomPassWord: e.detail.value,
		});
	},
	create: function() {
    let self = this;
    let nickName = wx.getStorageSync('wsUserInfo')&&wx.getStorageSync('wsUserInfo').nickName;
    let nowTime = new Date();
		if (nowTime - this.data.tapTime < 1000) {
			return;
		}
    if (!self.data.roomName) {
      wx.showModal({
        title: '提示',
        content: '房间名称不能为空',
        showCancel: false,
      });
      return;
    }
		if (/[<>*{}()^%$#@!~&= ]/.test(self.data.roomName)) {
			 wx.showModal({
				title: '提示',
				content: '名称不能为空或包含特殊字符',
        showCancel: false,
						});
			return;
    }
    if (self.data.roomPassWord.length > 11) {
      wx.showModal({
        title: '提示',
        content: '房间密码不能超过11位数字',
        showCancel: false,
      });
      return;
    }
    app.globalData.roomPassWord = self.data.roomPassWord;  
    const url = `../room/room?type=create&roomName= ${self.data.roomName}&userName=${nickName}`;
		wx.redirectTo({
			url,
		});
		wx.showToast({
			title: '进入房间',
			icon: 'success',
      duration: 1000,
    });
    self.setData({ tapTime: nowTime });
	},
	onLoad: function (options) {
		this.setData({
      userName: options.userName || '',			
    });
	},
});